
require "Logic/CtrlManager"
require "Controller/PromptCtrl"
require "Controller/LearnCtrl"

GameMain = {};
local this = GameMain;
local LuaHelper = LuaFramework.LuaHelper
local testView
local lastTime = 0

function GameMain.Main()
    print('hankangwen Game.Main')


    local ctrl = CtrlManager.GetCtrl(CtrlNames.Learn);
    if ctrl ~= nil then
        ctrl:Awake();
    end
    
    -- local ctrl = CtrlManager.GetCtrl(CtrlNames.Learn);
	-- print("hankangwen0001 logic start", (ctrl ~= nil), CtrlNames.Learn)
    -- if ctrl ~= nil then
    --     ctrl:Awake();
    -- end

    -- resMgr = LuaHelper.GetResManager()
    -- resMgr:LoadPrefab('test', {'TestView'}, GameMain.OnLoadFinish)
    
    -- network
    -- local networkMgr = LuaHelper.GetNetManager()    
    -- AppConst.SocketPort = 888;
    -- AppConst.SocketAddress = "127.0.0.1";
    -- networkMgr:SendConnect();

    -- sound
    -- soundMgr = LuaHelper.GetSoundManager()
    -- -- soundMgr:PlayBacksound('Audios/BgmLogin', true)
    -- soundMgr:PlayBackSound("sounds", "bgmlogin")
    -- -- soundMgr:PlaySound("sounds", "bgmlogin")
    -- UpdateBeat:Add(this.Update, self)
end

function GameMain.Update()
    -- if Time.time>5 then
    --     soundMgr:StopBackSound()
    -- end

    -- if Time.time - lastTime > 1 then
    --     soundMgr:PlaySound("sounds", "click")
    --     lastTime = Time.time
    -- end
end

function GameMain.OnLoadFinish(objs)
    -- 显示面板
    testView = GameObject.Instantiate(objs[0])
    local uiRoot = GameObject.FindGameObjectWithTag('UIRoot')
    -- local uiRoot = GameObject.Find('UIRoot')
    testView.transform:SetParent(uiRoot.transform)
    testView.transform.localScale = Vector3.one
    testView.transform.localPosition = Vector3.zero

    -- 事件处理
    local testBtn = testView.Find('TestBtn')
	print('GameMain.OnLoadFinish', testBtn)
    UIEvent.AddButtonClick(testBtn, this.OnClick)
end

function GameMain.OnClick()
    print('GameMain.OnClick()')
end